/**
 * 本质上就是最小生成树，然后再求一个特殊点到树的最短距离
 * 排序以后配合并查集即可。
 */
#include <bits/stdc++.h>
using namespace std;

using Real = long double;
using vi = vector<int>;

struct uf_t{
vi father;
void init(int n){father.assign(n+1,0);for(int i=1;i<=n;++i)father[i]=i;}
int find(int k){return k==father[k]?k:father[k]=find(father[k]);}
void unite(int x, int y){father[find(y)] = find(x);}
}U;

struct Point {
    Real x;
    Real y;
};

Real dist(const Point & A, const Point & B){
    auto x = A.x - B.x, y = A.y - B.y;
    return sqrt(x * x + y * y);
}

vector<Point> A;
Point P0;
int N;

struct _t{
    int i;
    int j;
    Real d;
};
vector<_t> T;

void work(){
    cin >> P0.x >> P0.y;
    cin >> N;
    A.assign(N, {});
    for(auto & p : A) cin >> p.x >> p.y;

    T.clear();
    T.reserve(N * N / 2 + 100);
    for(int i=0;i<N;++i)for(int j=i+1;j<N;++j){
        T.push_back({i, j, dist(A[i], A[j])});
    }

    sort(T.begin(), T.end(), [](const _t & a, const _t & b){
        if(a.d != b.d) return a.d < b.d;
        if(a.i != b.i) return a.i < b.i;
        return a.j < b.j;
    });

    U.init(N);
    int left = N;
    Real ans = 0;
    for(const auto & t : T){
        if(U.find(t.i) == U.find(t.j)) continue;

        U.unite(t.i, t.j);
        ans += t.d;
        if(0 == --left) break;
    }

    Real tmp = 1E100;
    for(const auto & p : A){
        auto t = dist(P0, p);
        if(t < tmp) tmp = t;
    }

    ans += tmp;
    cout << fixed << setprecision(12) << ans << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    cin >> nofkase;
    while(nofkase--) work();	
    return 0;
}